import {http} from "@/utils/http";
import {message} from "@/utils/message";

// 这里编写 后端接口 HTTP请求代码

export type BaseResponse<T> = {
  errorMsg: string;
  errorCode: string;
  success: boolean;
  content: T;
}
export type ProcessItemDTO = BaseResponse<{
  data: [{
    /** 头像 */
    name: string;
    /** 用户名 */
    no: string;
    /** 昵称 */
    formInstanceId: string;
    /** 当前登录用户的角色 */
    // roles: Array<string>;
    /** 按钮级别权限 */
    id: BigInteger;
    /** `token` */
    corpId: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    creator: string;
    creatorName: string;
  }]
}>;

// let HanjunTest extend BaseResponse<HanjunTest> {}
export type HanjunTest = BaseResponse<{
  data: [{
    /** 头像 */
    flowName: string;
    /** 用户名 */
    flowCode: string;
    /** 昵称 */
    updateTime: string;
    /** 当前登录用户的角色 */
    // roles: Array<string>;
    /** 按钮级别权限 */
    id: BigInteger;
    /** `token` */
    version: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    xmlString: string
  }]
}>;

export type ProcessIdData = {
  id: string;  // 假设id是字符串类型
  flowCode: string;
}

export type ResponseSimpleDTO = {
  success: boolean;  // 假设id是字符串类型
  errorMessage: string;
  errorCode: string;
  errorMsg: string;
}

export type RefreshTokenResult = {
  success: boolean;
  data: {
    /** `token` */
    accessToken: string;
    /** 用于调用刷新`accessToken`的接口时所需的`token` */
    refreshToken: string;
    /** `accessToken`的过期时间（格式'xxxx/xx/xx xx:xx:xx'） */
    expires: Date;
  };
};

/** 登录4 test */
export const getLogin2 = (data?: object) => {
  // debugger
  console.log("getLogin2");
  // 要求支持跨域
  // return http.request<UserResult>("post", "/login", { data, withCredentials: true });
  // 未要求支持跨域
  return http.request<HanjunTest>("post", "http://123.57.78.161:8081/palm/mock/demo.json", {
    data,
    withCredentials: true
  });
};

/**
 * 流程定义列表
 * @param data
 */
export const queryProcessList = (data?: object) => {
  // debugger
  console.log("queryProcsDefList");
  // 要求支持跨域
  //把请求格式改为 form-data
  // return http.request<UserResult>("post", "/login", { data, withCredentials: true });
  return http.request<ProcessItemDTO>("post", "http://123.57.78.161:8081/palm/process/query.json", {
    data,
    withCredentials: true
  })
};

/**
 * 发起流程实例
 * @param data
 */
export const checkProcessAndSyncData = (data?: object) => {
  // debugger
  console.log("checkProcessAndSyncData");
  // 要求支持跨域
  // return http.request<UserResult>("post", "/login", { data, withCredentials: true });
  return http.request<HanjunTest>("post", "http://123.57.78.161:8081/palm/process/syncData.json" /*+ data.id*/, {
    data,
    withCredentials: true
  });
};


/**
 * 发布流程
 * @param data
 */
export const publishProcsDef2 = (data?: ProcessIdData) => {
  // debugger
  console.log("publishProcsDef");
  // 要求支持跨域
  // return http.request<UserResult>("post", "/login", { data, withCredentials: true });
  return http.request<HanjunTest>("get", "http://123.57.78.161:8081/flow/definition/publish/1285376095981539328" /*+ data.id*/, {
    withCredentials: true
  });
};

/**
 * http://123.57.78.161:8081/flow/definition/xmlString/1285376095981539328
 * @param data
 */
export const getProcsDefSchema2 = (data?: ProcessIdData) => {
  // debugger
  console.log("getProcsDefSchema");
  // 要求支持跨域
  // return http.request<UserResult>("post", "/login", { data, withCredentials: true });
  return http.request<HanjunTest>("get", "http://123.57.78.161:8081/flow/definition/xmlString/1285376095981539328" /*+ data.id*/, {
    withCredentials: true
  });


};


